<?
require_once("class.createEvent.php");
session_start();
require_once('config.php');
require_once('classes/class.jira.php');
require_once('classes/class.phpmailer.php');
include("classes/connect.php");
ini_set('display_errors', 'On');

$username = $_SESSION["Juname"];
$pass = $_SESSION["Jpass"];
$jiraid=$_GET['jiraid'];
$id=$_GET['id'];
$current=$_GET['currentstatus'];
$currentassignee=$_GET['currentassignee'];
$vcode=$_GET['vcode'];

unset($_SESSION['curstatus']);
$_SESSION['curstatus']=$_GET['curstatus'];

unset($_SESSION['pageno']);
$_SESSION['pageno']=$_GET['pageno'];

unset($_SESSION['assignee']);
$_SESSION['assignee']=$_GET['assignee'];

unset($_SESSION['post']);
$_SESSION['post']=$_GET['post'];

unset($_SESSION['priority']);
$_SESSION['priority']=$_GET['priority'];

unset($_SESSION['fromDate']);
$_SESSION['fromDate']=$_GET['fromDate'];

unset($_SESSION['toDate']);
$_SESSION['toDate']=$_GET['toDate'];
//var_dump($_SESSION['pageno']); exit();

	$popstatus=$_POST["status"];
	$poppost=$_POST["post"];
	$popassignee=$_POST["assignee"];
	$popsummary=$_POST["summary"];
	$popemail=$_POST["email"];
	$popname=$_POST["name"];
	$popfname=$_POST["firstname"];
	$poplname=$_POST["lastname"];
	$popaddress1=$_POST["address1"];
	$popaddress2=$_POST["address2"];
	$poptp=$_POST["tp"];
	$popmobile=$_POST["mobile"];
	$popcity=$_POST["city"];
	$popnic=$_POST["nic"];
	$popemailcontent=$_POST['emailcontent'];
	$popemailcontentsubject=$_POST['emailcontentsubject'];
	$popofferemailcontent=$_POST['emailcontentoffer'];
	$popofferemailcontentsubject=$_POST['emailcontentoffersubject'];
	$popselectedemailcontent=$_POST['emailcontentselected'];
	$popselectedemailcontentsubject=$_POST['emailcontentselectedsubject'];
	$poppriority=$_POST['priority'];
	
	$config->username= $username;
	$config->password= $pass;
	$config->port= "";
	$config->host= $host;
	
	$queryIssue = new Jira($config);
    
	if(isset($_POST["referee"])){
		$sqlreferee="UPDATE trn_emaildetails SET 
								verified = '1'
								where id='".$id."'";
		mysql_query($sqlreferee);
	
	}
		
//functions
function getquery($username,$pass,$host,$projectid){
	$config->username= $username;
	$config->password= $pass;
	$config->port= "";
	$config->host= $host;
	$query->id = $projectid;
		$queryIssue = new Jira($config);
		$array=$queryIssue->queryIssue($query);
		$response = json_decode($array->responseBody);
		return $response;
}

function sendApplicantMail($interviewdate,$interviewtimefrom,$interviewtimeto,$interviewdateinform,$applicantname,$AddReplyTo,$gmailuser,$sendto,$fromname,$interviewcalledsubject,$poppost,$testtype,$vcode,$referee){
	$a=str_replace('{APPLICANT NAME}',$applicantname,$interviewdateinform);
	$b=str_replace('{JOB POST}',$poppost,$a);
	$c=str_replace('{DATE}',$interviewdate,$b);
	$d=str_replace('{TIMEFROM}',$interviewtimefrom,$c);
	$e=str_replace('{TIMETO}',$interviewtimeto,$d);
	$f=str_replace('{TEST TYPE}',$testtype,$e);
	$g=str_replace('{VCODE}',$vcode,$f);
	$h=str_replace('{REFERENCE}',$referee,$g);
	$i=str_replace("{TEST TYPE}",$testtype,$interviewcalledsubject);
	
	//var_dump($interviewtimeto); exit;
	$mail= new PHPMailer();	
	$body= $h;
	$mail->AddReplyTo($AddReplyTo);
	$mail->SetFrom($gmailuser,"HR - Eyepax IT Consulting");
	$address = $sendto;
	$mail->AddAddress($address, $fromname);
	$mail->Subject    = $i;
	$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
	$mail->MsgHTML($body);
	if(!$mail->Send()) {
	  echo "Mailer Error: " . $mail->ErrorInfo;
	} else {
	  echo "Message sent!";
	}

}
function sendInviteesIcal($inviteelistEn,$interviewdate,$interviewtimefrom,$interviewtimeto,$applicantname,$notifyinterview,$post,$inviteecalendarsubject,$location,$testtype,$vcode,$projectname,$popassignee){
	$sql="SELECT * from trn_attachments where id=".$_GET['id'];
	$sq=mysql_query($sql);
	
	$link='';
	if(mysql_num_rows($sq)==0){
		$link="The Applicant has not sent an attachment";
	}
	else{
		while($row = mysql_fetch_array($sq)){
			$url = $row['name'];
			$url = explode("http://eyepax.com/sites/default/files/cv/", $url);
			
			if(isset($url[1])){
				$name = $url[1];
				$link = $row['name'];
			}else{
				$name = $row['name'];
				$link = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/Attachments/".$row['name'];
			}
			
			//var_dump($row);
			//$link =$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/Attachments/".$row['name']."<br>";
			
		}
	}
	

		
	$link2=$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/applicant-view.php?vcode=".$vcode;
	// formatting The Description	
	$a=str_replace('{DATE}',$interviewdate,$notifyinterview);
	$b=str_replace('{TIMEFROM}',$interviewtimefrom,$a);
	$c=str_replace('{APPLICANT NAME}',$applicantname,$b);
	$d=str_replace('{LINK}',$link,$c);
	$e=str_replace('{TIMETO}',$interviewtimeto,$d);
	$f=str_replace('{TEST TYPE}',$testtype,$e);
	$g=str_replace('{FORMLINK}',$link2,$f);
	$g1=str_replace('{PROJECT}',$projectname,$g);
	$revisedinterviewtimefrom  = DATE("H:i", STRTOTIME($interviewtimefrom));
	$revisedinterviewtimeto  = DATE("H:i", STRTOTIME($interviewtimeto));
	
	$inviteelist= str_replace('%40','@',$inviteelistEn);
	//$popassignee=urldecode($popassigneeEn);
	
	//var_dump($inviteelist); exit;
	foreach($inviteelist as $value){
		$param = explode("src=", $value);
		$rest = substr($value, 0, -17);
		$rest = substr($rest,4);
		//var_dump($rest); 
		$invitees[]=$rest;	
	}
		if(empty($invitees)){
			$invitees[]=$popassignee.'@eyepax.com';
		}
		else{
			array_push($invitees, $popassignee."@eyepax.com"); 
		}
	echo '<pre>';
	print_r($invitees);
	echo "<br>";
	$h=str_replace('{APPLICANT NAME}',$applicantname,$inviteecalendarsubject);
	$i=str_replace('{JOB POST}',$post,$h);
	$j=str_replace('{TEST TYPE}',$testtype,$i);
	
	$event = new GoogleCalendar();
    $event->title = $j;
    $event->content = $g1;
    $event->where = $location;
    var_dump( array('Date' => date('Y-m-d',STRTOTIME($interviewdate)), 'Time' => $revisedinterviewtimefrom));
    $event->start = array('Date' => date('Y-m-d',STRTOTIME($interviewdate)), 'Time' => $revisedinterviewtimefrom);
    $event->end = array('Date' => date('Y-m-d',STRTOTIME($interviewdate)), 'Time' => $revisedinterviewtimeto);
    $event->who = $invitees;
    
    $event->sendNotification = true;
    $event->sendReminder = true;
    
    $event->create();
	

}


function getDisplay($username,$pass,$host){
        $config->username= $username;
        $config->password= $pass;
        $config->port= "";
        $config->host= $host;

        $queryIssue = new Jira($config);
        $array=$queryIssue->getUser($username);
        $response = json_decode($array->responseBody);
        return $response;
        }
        
        function getDisplay2($username,$pass,$host,$name){
        $config->username= $username;
        $config->password= $pass;
        $config->port= "";
        $config->host= $host;

        $queryIssue = new Jira($config);
        $array=$queryIssue->getUser($name);
        $response = json_decode($array->responseBody);
        return $response;
        }
 // add comment - {tab4}
 if(isset($_POST['txtComment']) && $_POST['txtComment']!=''){
    
    $config->host= $host;
    $config->port= "";     
    $config->username = $_SESSION["Juname"];
    $config->password = $_SESSION["Jpass"];
    $queryAddComment = new Jira($config);    

    $commnt_data->body = $_POST['txtComment'];
    $comment_response = $queryAddComment->addComment($jiraid, $commnt_data); 
    
//   if($response->responseBody){
//       $sqlquery = "UPDATE trn_emaildetails SET 
//                            modifiedBy = '". $_SESSION['jiraUserFullName'] ."',
//                            modifiedDate = '". time() ."' 
//							where id='".$_REQUEST['id']."'";
//    
//	mysql_query($sqlquery);
//    
//       
//  }
  
 }

	// updating activity table to record history
	if($popassignee!==$currentassignee){
            $resolution->transition->id =$popstatus;
		$queryIssue->updateTransition($jiraid,$resolution);
		$query->id = $jiraid;
		$array=$queryIssue->queryIssue($query);
		$response = json_decode($array->responseBody);
               // var_dump($response);
                
               //  $display=  getDisplay($username, $pass, $host);
                 
		$revisedstatus=$response->issues[0]->fields->status->name;
				$assigneedescription="changed Assignee to <b>".$popassignee."</b> by <b>".$username.'</b>';
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$assigneedescription."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                       $display=  getDisplay($username, $pass, $host);
                        $display2=  getDisplay($username, $pass, $host,$popassignee);
                          // echo $display->displayName;          
                                 $emaildetailssql="UPDATE trn_emaildetails SET 
									currentAssignee = '".$popassignee."',
                                                                        currentAssigneeName='".$display2->displayName."',
                                                                        modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
	
	}
	if($popstatus!==$current){
		$resolution->transition->id =$popstatus;
		$queryIssue->updateTransition($jiraid,$resolution);
		$query->id = $jiraid;
		$array=$queryIssue->queryIssue($query);
		$response = json_decode($array->responseBody);
		$revisedstatus=$response->issues[0]->fields->status->name;
                
                $display=  getDisplay($username, $pass, $host);
                
		switch($revisedstatus){
			case $action_ShortList:
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_two_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_ShortList."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_Interviewed:
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_three_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_Interviewed."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_Tested:
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_four_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_Tested."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
				break;
			case $action_Selected:
				
				$postquery="select * from sys_jobposts where code='".$poppost."'";
				$execpostquery =mysql_query($postquery);
				$posts = mysql_fetch_array($execpostquery);
				if(isset($_POST["emailsendselected"])){
					if($popstatus==71 OR $popstatus==111 OR $popstatus==231){
					sendApplicantMail(NULL,NULL,NULL,$popselectedemailcontent,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$popselectedemailcontentsubject,$posts['postname'],NULL,NULL,NULL);
					}
				}
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_five_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				
				mysql_query($activitysql);
                                
                                $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_Selected."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_Rejected:
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_six_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_Rejected."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_Offered:
			
				$postquery="select * from sys_jobposts where code='".$poppost."'";
				$execpostquery =mysql_query($postquery);
				$posts = mysql_fetch_array($execpostquery);
				
				$query->key=$jiraid;
				$queryrefer=new Jira($config);
				$queryrefer1=$queryrefer->queryIssue($query);
				$queryrefer2=json_decode($queryrefer1->responseBody);
				if(isset($_POST["emailsendoffer"])){
					if($popstatus==131){
					sendApplicantMail($_POST['joindate'],NULL,NULL,$popofferemailcontent,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$popofferemailcontentsubject,$posts['postname'],NULL,NULL,$queryrefer2->issues[0]->key);
					}
				}
				$emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_Offered."',expectedJoinDate = '".$_POST['joindate']."'
									where id='".$id."'";
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_seven_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
				mysql_query($emaildetailssql);
				break;
			case $action_InterviewCalled:
				
				$projectname=getquery($username,$pass,$host,$_GET['jiraid'])->issues[0]->key;
				$postquery="select * from sys_jobposts where code='".$poppost."'";
				$execpostquery =mysql_query($postquery);
				$posts = mysql_fetch_array($execpostquery);
			
				sendApplicantMail($_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$interviewdateinform,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$interviewcalledsubject,$posts['postname'],NULL,$vcode,NULL);
				sendInviteesIcal($_POST['notify'],$_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$popfname,$notifyinterview,$poppost,$inviteecalendarsubject,$_POST['locinterview'],NULL,$vcode,$projectname,$popassignee);
								
				$Sdatetime=$_POST['interviewdate'].$_POST['timepickerFrom'];
				$Sformattime=strtotime($Sdatetime);
				$Edatetime=$_POST['interviewdate'].$_POST['timepickerTo'];
				$Eformattime=strtotime($Edatetime);
				
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_eight_des."',
											modifiedBy = '".$username."',
											SDateTime = '".$Sformattime."',
											EDateTime = '".$Eformattime."',
											location = '".$_POST['loc']."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                 $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_InterviewCalled."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_TestCalled:
				
				$projectname=getquery($username,$pass,$host,$_GET['jiraid'])->issues[0]->key;
				$postquery="select * from sys_jobposts where code='".$poppost."'";
				$execpostquery =mysql_query($postquery);
				$posts = mysql_fetch_array($execpostquery);
				
				if($popstatus==41){
				sendApplicantMail($_POST['testdate'],$_POST['timepickertestFrom'],$_POST['timepickertestTo'],$testdateinform,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$testcalledsubject,$posts['postname'],$_POST['type'],$vcode,NULL);
				}
				else{
				sendApplicantMail($_POST['testdate'],$_POST['timepickertestFrom'],$_POST['timepickertestTo'],$testdateinform2,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$testcalledsubject,$posts['postname'],$_POST['type'],$vcode,NULL);
				}
				sendInviteesIcal($_POST['notifytest'],$_POST['testdate'],$_POST['timepickertestFrom'],$_POST['timepickertestTo'],$popfname,$notifytest,$poppost,$testinviteecalendarsubject,$_POST['loctest'],$_POST['type'],$vcode,$projectname,$popassignee);
				
				$Sdatetime=$_POST['testdate'].$_POST['timepickertestFrom'];
				$Sformattime=strtotime($Sdatetime);
				$Edatetime=$_POST['testdate'].$_POST['timepickertestTo'];
				$Eformattime=strtotime($Edatetime);
				
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_nine_des."',
											modifiedBy = '".$username."',
											SDateTime = '".$Sformattime."',
											EDateTime = '".$Eformattime."',
											location = '".$_POST['loc']."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                 $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_TestCalled."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
                                
			case $action_Joined:
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_ten_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                
                                  $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_TestCalled."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_FinalInterviewCalled:
				
				$projectname=getquery($username,$pass,$host,$_GET['jiraid'])->issues[0]->key;
				$postquery="select * from sys_jobposts where code='".$poppost."'";
				$execpostquery =mysql_query($postquery);
				$posts = mysql_fetch_array($execpostquery);
				$postquery1="select * from trn_emaildetails where id='".$id."'";
				$execpostquery1 =mysql_query($postquery1);
				$filled = mysql_fetch_array($execpostquery1);
				
				if($popstatus==261){//mail change prompt					
					if(isset($_POST["emailsend"])){
						sendApplicantMail($_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$popemailcontent,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$popemailcontentsubject,$posts['postname'],NULL,$vcode,NULL);
					}
					sendInviteesIcal($_POST['notify'],$_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$popfname,$notifyfinalinterview,$poppost,$finalinviteecalendarsubject,$_POST['locinterview'],NULL,$vcode,$projectname,$popassignee);				
				}
				else{//default mail
					if($filled['infotrue']==1){
						sendApplicantMail($_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$finalinterviewdateinform,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$finalinterviewsubject,$posts['postname'],NULL,$vcode,NULL);
						sendInviteesIcal($_POST['notify'],$_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$popfname,$notifyfinalinterview,$poppost,$finalinviteecalendarsubject,$_POST['locinterview'],NULL,$vcode,$projectname,$popassignee);	
					}
					else{
						sendApplicantMail($_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$finalinterviewdateinform2,$popfname,$AddReplyTo,$gmailuser,$popemail,$fromname,$finalinterviewsubject,$posts['postname'],NULL,$vcode,NULL);
						sendInviteesIcal($_POST['notify'],$_POST['interviewdate'],$_POST['timepickerFrom'],$_POST['timepickerTo'],$popfname,$notifyfinalinterview,$poppost,$finalinviteecalendarsubject,$_POST['locinterview'],NULL,$vcode,$projectname,$popassignee);											
					}
				}
				
				$Sdatetime=$_POST['interviewdate'].$_POST['timepickerFrom'];
				$Sformattime=strtotime($Sdatetime);
				$Edatetime=$_POST['interviewdate'].$_POST['timepickerTo'];
				$Eformattime=strtotime($Edatetime);
			
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_eleven_des."',
											modifiedBy = '".$username."',
											SDateTime = '".$Sformattime."',
											EDateTime = '".$Eformattime."',
											location = '".$_POST['loc']."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                                 $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_FinalInterviewCalled."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
                                
				break;
			case $action_FinalInterviewed:
				$activitysql = "INSERT INTO trn_activity SET 
											mainId = '".$id."',
											status = '".$revisedstatus."',
											action = '".$revisedstatus."',
											description = '".$action_twelve_des."',
											modifiedBy = '".$username."',
											modifiedDate = '".time()."'
								";
				mysql_query($activitysql);
                                
                               $emaildetailssql="UPDATE trn_emaildetails SET 
									currentStatus = '".$action_FinalInterviewed."',modifiedBy = '".$display->displayName."',modifiedDate = '".time()."' 
									where id='".$id."'";
                                mysql_query($emaildetailssql);
				break;			
		}
	}
	else{
		$revisedstatus=$popstatus;
	}
	//#################################PLEASE CHANGE ASAP##################################
	
	$postqueryform="select * from sys_jobposts where code='".$poppost."'";
	$execpostqueryform =mysql_query($postqueryform);
	$postsform = mysql_fetch_array($execpostqueryform);
	$applied=$postsform['id'];
	
	if($poppost=="DOTNET"){
		$applied=1;
	}
	$priority->set->name = $poppriority;
	$update->update->priority= array($priority);
	$queryIssue->updateIssue($update,$_GET['jiraid']);
	
	
	$data->fields->summary=$popsummary;
	$data->fields->assignee->name=$popassignee;
	
	$queryIssue->updateIssue($data,$_GET['jiraid']);
	$query->id=$_GET['jiraid'];
	$array=$queryIssue->queryIssue($query);
	$response = json_decode($array->responseBody);
	$sqlquery = "UPDATE trn_emaildetails SET 
						
							applicantName = '".$popname."',
							fname = '".$popfname."',
							lname = '".$poplname."',						
							
							currentSummary = '".$popsummary."',
							priority = '".$poppriority."',
							email = '".$popemail."',
							nic = '".$popnic."',
							mobileNo = '".$popmobile."',
							appliedFor = '".$applied."',
							city = '".$popcity."',
							telephone = '".$poptp."',
							post = '".$poppost."',
							address1 = '".$popaddress1."',
							address2 = '".$popaddress2."'
                           
                           
							where id='".$id."'";
    
	mysql_query($sqlquery);
	
	
    
?>


<html>
    <script type='text/javascript'>
        window.opener.location.reload();
        
//    window.opener.document.location.href = '<?php echo $_GET['parent'];?>';
//	window.onunload  = function (e) {
//    //window.opener.location.reload();
//    
//        window.opener.document.location.href = '<?php echo $_GET['parent'];?>';
//	};

    
    self.close();
    </script>
</html>